#include <iostream>
#include <cstdio>
using namespace std;
struct ma
{
    int a,b,c,d;
};
ma data[32768*2+10];
int r,n,m;
inline int lc(int i) {return i<<1;}
inline int rc(int i) {return lc(i)^1;}
ma operator*(ma a,ma b)
{
    ma t;
    t.a=(a.a*b.a+a.b*b.c)%r;
    t.b=(a.a*b.b+a.b*b.d)%r;
    t.c=(a.c*b.a+a.d*b.c)%r;
    t.d=(a.c*b.b+a.d*b.d)%r;
    return t;
}
void product(ma &ret,ma A,ma B)
{
	ret.a = (A.a*B.a+A.b*B.c)%r;
	ret.b = (A.a*B.b+A.b*B.d)%r;
	ret.c = (A.c*B.a+A.d*B.c)%r;
	ret.d = (A.c*B.b+A.d*B.d)%r;
}
ma query(int p,int left,int right,int l,int rn)
{
	if(left==l&&right==rn)return data[p];
	int mid = (left+right)>>1;
	if(rn<=mid)return query(lc(p),left,mid,l,rn);
	else if(l>mid)return query(rc(p),mid+1,right,l,rn);
	return query(lc(p),left,mid,l,mid)*query(rc(p),mid+1,right,mid+1,rn);
}
void print(ma t)
{
    printf("%d %d\n%d %d\n",t.a,t.b,t.c,t.d);
}
int main()
{
    int pos,i,t1,t2;
    while(cin>>r>>n>>m)
    {
        for(pos=1;pos<r;pos<<=1);
        for(i=0;i<n;i++)
        {
            scanf("%d%d%d%d",&data[pos+i].a,&data[pos+i].b,&data[pos+i].c,&data[pos+i].d);
        }
        for(i=pos-1;i;i--)
        {
          //  product(data[i],data[lc(i)],data[rc(i)])
            data[i]=data[lc(i)]*data[rc(i)];
       //     print(data[i]);
        }
        while(m--)
        {
            scanf("%d%d",&t1,&t2);
            print(query(1,1,pos,t1,t2));
            if(m)cout<<endl;
        }
    }
    return 0;
}
